package com.example.starter.mystarter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Deyou
 * @Date: 2021/4/9
 */
//配置类
@Configuration
//开启HelloProperties类配置属性，并将HelloProperites类注入到容器中
@EnableConfigurationProperties(PersonProperties.class)
//判断当前类是否存在HelloService
@ConditionalOnClass(PersonService.class)
//Web 应用才生效
@ConditionalOnWebApplication
public class PersonAutoConfiguration {
    @Autowired
    PersonProperties personProperties;
    //把 Service 注入到Spring 容器。
    @Bean
    PersonService personService(){
        PersonService personService = new PersonService();
        personService.setName(personProperties.getName());
        return personService;
    }
}
